package com.bookstore.bauhinia.evaluation.service.impl;

import com.bookstore.bauhinia.evaluation.service.EvaluationService;
import com.bookstore.bauhinia.mapper.EvaluationMapper;
import com.bookstore.bauhinia.pojo.Evaluation;
import com.bookstore.bauhinia.pojo.EvaluationExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lzo
 */
@Service
public class EvaluationServiceImpl implements EvaluationService {
    @Resource
    private EvaluationMapper evaluationMapper;

    @Override
    public Evaluation selectByPrimaryKey(Integer id) {
        return evaluationMapper.selectByPrimaryKey(id);
    }

    @Override
    public int insert(Evaluation record) {
        return evaluationMapper.insertSelective(record);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return evaluationMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKey(Evaluation record) {
        return evaluationMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Evaluation> getAllEvaluations() {
        return evaluationMapper.selectByExample(new EvaluationExample());
    }

    @Override
    public List<Evaluation> getEvaluationsByBookId(Integer bookId) {
        EvaluationExample example = new EvaluationExample();
        EvaluationExample.Criteria criteria = example.createCriteria();
        criteria.andBookIdEqualTo(bookId);
        return evaluationMapper.selectByExample(example);
    }
}